package com.shengsiyuan.protobuf;

public class TestProtoBuf {

    public static void main(String args[]) throws Exception {

        // 机器A
        DataInfo.Student student = DataInfo.Student.newBuilder()
                                                    .setName("张三")
                                                    .setAddress("北京")
                                                    .setAge(20)
                                                    .build();

        // 转换成字节数组
        byte[] student2ByteArray = student.toByteArray();

        /**
         * 网络传输
         */

        // 机器B
        DataInfo.Student student1 = DataInfo.Student.parseFrom(student2ByteArray);
        System.out.println(student1);
        System.out.println(student1.getName());
        System.out.println(student1.getAddress());
        System.out.println(student1.getAge());

    }
}
